<template>
    <div class="search-box">
        <el-icon color="#999" size="18px">
            <Search />
        </el-icon>
        <el-input clearable v-model="keyword" placeholder="搜索您喜欢的..." @clear="onClear"></el-input>
        <button class="search-btn" @click="onSearch()">搜索</button>
    </div>

    <div class="hot-keyword" :style="{
        color: props.color,
    }">
        热门搜索:
        <div class="keyword-item" v-for="item in keywords" :key="item" @click="onSearch(item)">
            {{ item }}
        </div>
    </div>
</template>
<script setup>
import { Search } from "@element-plus/icons-vue";

const props = defineProps({
    color: {
        type: String,
        default: "#999",
    },
});

const keywords = ref([
    "沙发",
    "柜子",
    "医疗",
    "灭火器",
    "储能设备",
    "桌子",
    "植物",
    "配电柜",
]);

const emits = defineEmits(["search"]);
const keyword = ref("");

const onSearch = (item) => {
    item && (keyword.value = item);
    emits("search", keyword.value);
};

const onClear = () => {
    emits("search", keyword.value);
}
</script>
<style lang="scss" scoped>
.search-box {
    display: flex;
    align-items: center;
    width: 800px;
    height: 50px;
    background: #ffffff;
    border-radius: 6px;
    overflow: hidden;
    margin: 81px auto 0;

    :deep(.el-icon) {
        padding: 0 15px;
        box-sizing: content-box;
    }

    :deep(.el-input) {
        width: 100%;
        height: 100%;
        background: #ffffff;
        border-radius: 6px;
        outline: none;
        border: none;
        font-size: 16px;

        .el-input__wrapper {
            box-shadow: none;
        }

        .el-input__clear {
            font-size: 20px;
            width: 24px;
            height: 24px;
        }

        &::placeholder {
            color: #999;
        }
    }

    .search-btn {
        width: 100px;
        height: 50px;
        border: none;
        background-color: #5085fb;
        font-weight: bold;
        font-size: 20px;
        color: #ffffff;
        line-height: 30px;
        cursor: pointer;
        flex-shrink: 0;
    }
}

.hot-keyword {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 19px;
    color: #999;

    .keyword-item {
        margin-left: 15px;
        cursor: pointer;

        &:hover {
            color: #5085fb;
        }
    }
}
</style>
